/**
 * 腾讯地图api服务接口
 * @author lian
 */

import { Method } from '../enum'
import { TXMapApi } from '@/common/constants'
import type { LocationCode } from '@/common/types/request'

const key = import.meta.env.HOPE_TX_MAP_KEY

/**
 * 地址转换为经纬度
 * @param address 地址
 * @author lian
 */
export const addressToCodeService = async (address: string) => {
  const { result } = await useRequest({
    method: 'GET',
    url: TXMapApi.TX_MAP_BASE,
    data: {
      address,
      key,
    },
  }) as any
  return result.location
}

/**
 * 经纬度转地址信息
 * @param location 经纬度
 * @author lian
 */
export const codeToAddressService = async (location: LocationCode) => {
  const data = await useRequest({
    method: Method.GET,
    url: TXMapApi.TX_MAP_BASE,
    data: {
      location,
      key,
    },
  }) as any

  console.log('转换地址:', data)
}
